#include <cstdlib>
#include <cstddef>

struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};

int* inorderTraversal(struct TreeNode* root, int* returnSize){
    int *arr = (int *)malloc(sizeof(int) * 101);
    *returnSize = 0;
    int top = 0;
    struct TreeNode **stk = (struct TreeNode **)malloc(sizeof(struct TreeNode *) * 101);
    while(root != NULL || top > 0){
        while(root != NULL){
            stk[top++] = root;
            root = root->left;
        }
        root = stk[--top];
        arr[(*returnSize)++] = root->val;
        root = root->right;
    }
    return arr;
}